package top.kaoshanji.p1ch05a;

/**
 * 代码清单-p1ch05a-123页a：带有实例变量和方法的枚举类
 * author kaoshanji
 * ^_^
 * create time 2025/2/17 17:46
 */
public enum Size {

    SMALL("S", "小号"),
    MEDIUM("M", "中号"),
    LARGE("L", "大号");

    private String abbr;
    private String title;

    Size(String abbr, String title) {
        this.abbr = abbr;
        this.title = title;
    }

    public String getAbbr() {
        return abbr;
    }

    public String getTitle() {
        return title;
    }

    public static Size fromAbbr(String abbr) {
        for (Size size: Size.values()) {
            if (size.getAbbr().equals(abbr)) {
                return size;
            }
        }
        return null;
    }

}
